package com.djx.基础;

import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
import org.junit.Test;

public class ZKGetData {

    ZooKeeper zooKeeper = new MyZookepper01().zooKeeper;

    @Test
    public void syncGetData() throws KeeperException, InterruptedException {
        byte[] data = zooKeeper.getData("/djx", false, null);
        System.out.println(new String(data));
        zooKeeper.close();
        System.out.println("zookeeper连接关闭");
    }

    @Test
    public void asyncGetData() throws KeeperException, InterruptedException {
       zooKeeper.getData("/djx", false, new AsyncCallback.DataCallback() {
            public void processResult(int i, String s, Object o, byte[] bytes, Stat stat) {
                System.out.println(i);
                System.out.println(o);
                System.out.println(new String(bytes));
                System.out.println(stat.getNumChildren());
            }
        },"I am 查询成功");
        zooKeeper.close();
        System.out.println("zookeeper连接关闭");
    }
}
